package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.project.system.domain.vo.MyCyhVipVo;
import com.laowang.project.system.domain.vo.VipVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhVip;
import com.laowang.project.system.service.MyCyhVipService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 会员级别Controller
 *
 * @author laowang
 * @date 2023-06-01
 */
@Api(tags = "会员级别接口")
@RestController
@RequestMapping("/vip")
public class MyCyhVipController extends BaseController {


    @Autowired
    private MyCyhVipService myCyhVipService;

    @ApiOperation(value = "小程序端 会员级别列表",notes = "")
    @GetMapping("/web/list")
    public AjaxResult  weblist() {

        List<MyCyhVip> list = myCyhVipService.selectMyCyhVipList(null);
        return AjaxResult.success("操作成功",list);
    }

    @ApiOperation(value = "小程序端 会员折扣",notes = "")
    @GetMapping("/web/discount/{id}")
    public AjaxResult  discount(@PathVariable("id" ) Integer id) {
        MyCyhVipVo myCyhVipVo = myCyhVipService.selectMyCyhVipDiscount(id);
        //<p><span style="color: rgb(255, 255, 255);">尊贵的车友朋友欢迎加入MC俱乐部，现在加入立马获得以下权益</span></p><p><br></p>
        if(myCyhVipVo.getLevel().equals(1)){
            List<VipVo> vips = myCyhVipVo.getVips();
            for (VipVo vip : vips) {
                if (vip.getAid().equals(24)){
                    String s = "<p><span style=\"color: rgb(255, 255, 255);\">名车群(名车会员)</span></p><p><br></p>";
                    String str =s + vip.getIntro();
                    vip.setIntro(str);
                }
            }
        }
        if(myCyhVipVo.getLevel().equals(2)){
            List<VipVo> vips = myCyhVipVo.getVips();
            for (VipVo vip : vips) {
                if (vip.getAid().equals(24)){
                    String s = "<p><span style=\"color: rgb(255, 255, 255);\">百万豪车群(银牌会员)</span></p><p><br></p>";
                    String str =s + vip.getIntro();
                    vip.setIntro(str);
                }
            }
        }
        if(myCyhVipVo.getLevel().equals(3)){
            List<VipVo> vips = myCyhVipVo.getVips();
            for (VipVo vip : vips) {
                if (vip.getAid().equals(24)){
                    String s = "<p><span style=\"color: rgb(255, 255, 255);\">千万级企业家群(金牌会员)</span></p><p><br></p>";
                    String str =s + vip.getIntro();
                    vip.setIntro(str);
                }
            }
        }
        if(myCyhVipVo.getLevel().equals(4)){
            List<VipVo> vips = myCyhVipVo.getVips();
            for (VipVo vip : vips) {
                if (vip.getAid().equals(24)){
                    String s = "<p><span style=\"color: rgb(255, 255, 255);\">亿级企业家俱乐部(砖石会员)</span></p><p><br></p>";
                    String str =s + vip.getIntro();
                    vip.setIntro(str);
                }
            }
        }
        if(myCyhVipVo.getLevel().equals(5)){
            List<VipVo> vips = myCyhVipVo.getVips();
            for (VipVo vip : vips) {
                if (vip.getAid().equals(24)){
                    String s = "<p><span style=\"color: rgb(255, 255, 255);\">荣誉副会长(副会长单位)</span></p><p><br></p>";
                    String str =s + vip.getIntro();
                    vip.setIntro(str);
                }
            }
        }
        return AjaxResult.success("操作成功",myCyhVipVo);
    }




    /**
     * 查询会员级别列表
     */
    @ApiOperation(value = "查询会员级别列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vip:list')")
    @GetMapping("/list")
        public TableDataInfo list(MyCyhVip myCyhVip) {
        startPage();
        List<MyCyhVip> list = myCyhVipService.selectMyCyhVipList(myCyhVip);
        return getDataTable(list);
    }

    /**
     * 导出会员级别列表
     */
    @ApiOperation(value = "导出会员级别列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vip:export')")
    @Log(title = "会员级别", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyCyhVip myCyhVip) {
        List<MyCyhVip> list = myCyhVipService.selectMyCyhVipList(myCyhVip);
        ExcelUtil<MyCyhVip> util = new ExcelUtil<MyCyhVip>(MyCyhVip.class);
        return util.exportExcel(list, "vip");
    }

    /**
     * 获取会员级别详细信息
     */
    @ApiOperation(value = "获取会员级别详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myCyhVipService.selectMyCyhVipById(id));
    }

    /**
     * 新增会员级别
     */
    @ApiOperation(value = "新增会员级别",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vip:add')")
    @Log(title = "会员级别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhVip myCyhVip) {
        return toAjax(myCyhVipService.insertMyCyhVip(myCyhVip));
    }

    /**
     * 修改会员级别
     */
    @ApiOperation(value = "修改会员级别",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vip:edit')")
    @Log(title = "会员级别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhVip myCyhVip) {
        return toAjax(myCyhVipService.updateMyCyhVip(myCyhVip));
    }

    /**
     * 删除会员级别
     */
    @ApiOperation(value = "删除会员级别",notes = "")
    @PreAuthorize("@ss.hasPermi('my:vip:remove')")
    @Log(title = "会员级别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhVipService.deleteMyCyhVipByIds(ids));
    }
}
